package com.wenli.graduate2022.wenliGreenShop.repository.mapper;

import com.wenli.graduate2022.wenliGreenShop.entity.Address;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

/**
 * @author HuangHai
 * @date 2021/9/27 14:25
 */
@Repository
public interface AddressMapper {

    @Results(id = "address",value={
            @Result(property = "addressRegionId",column = "address_regionId",//根据数据库中的address_regionId字段作为id条件，将查到的数据封装到addressRegionId属性里
                    one = @One(select = "com.wenli.graduate2022.wenliGreenShop.repository.mapper.AddressMapper.findById",
                    fetchType = FetchType.LAZY))//懒加载，除非详细查看，如调用get方法，才会进行sql执行（打印对象其实是只要重写toString方法也是调用了get方法）
    })
    @Select("select * from address where address_areaId = #{id} and address_areaId != address_regionId ") //因为该类的属性也有该类类型，所有查询会是递归查询，必须给他一个终止条件，不然会一直查到栈溢出
    Address findById(String id);
}
